package one.stand.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import one.stand.aop.ApiController;
import one.stand.enums.GlobalTypeEnums;
import one.stand.enums.LoginEnum;
import one.stand.model.CompanyModel;
import one.stand.model.ResultModel;
import one.stand.request.*;
import one.stand.response.GlobalConfigurationResponse;
import one.stand.response.LoginResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/crmApi/home")
@Api(description = "基础接口",tags="基础接口")
public class HomeController extends BaseController {

    @PostMapping("/wxLogin")
    @ApiOperation(value = "微信登陆接口")
    @ApiController(paramClass =WxLoginRequest.class )
    public ResultModel<LoginResponse> wxLogin(@RequestAttribute WxLoginRequest request, HttpServletResponse response) {
        request.setLoginProgramName(LoginEnum.CRM.getCode());
        ResultModel<LoginResponse> model = loginFegin.loginByWeixin(request);
        if (model.getData() != null) {
            response.setHeader("token", model.getData().getToken());
            response.setHeader("id", model.getData().getUserId().toString());
        }
        return model;
    }

    @PostMapping("/getWxPhone")
    @ApiOperation(value = "获取微信电话")
    @ApiController(isLogin = true,paramClass =GetWxPhoneRequest.class)
    public ResultModel<String> getWxPhone(@RequestAttribute GetWxPhoneRequest request){
        return loginFegin.getWxPhone(request);
    }


    @GetMapping("initial")
    @ApiOperation(value = "获取页面初始化配置")
    public ResultModel<List<GlobalConfigurationResponse>> initial() {
        return loginFegin.initial(new GlobalConfigurationRequest() {{
            setGlobalProgramName(LoginEnum.USER.getCode());
            setGlobalType(GlobalTypeEnums.HTML.getCode());
        }});
    }




}
